<?php

if(isset($_POST['filNameEdit']) && isset($_POST['filLinkEdit']) && isset($_POST['filIdParent']) && isset($UID)){
#if it is a dirAdd request

  $filNameEdit = $_POST['filNameEdit'];
  $filLinkEdit = $_POST['filLinkEdit'];
  $filIdParent = $_POST['filIdParent'];

  require_once $BASE_PATH . 'm/fil.php';

  $filcn = new FIL(DBHOST, DBUSER, DBPASS, DBNAME);

  $filcn->add($filIdParent, $filNameEdit, $filLinkEdit, $UID);

  require_once $BASE_PATH . 'm/dir.php';

  $dircn = new DIR(DBHOST, DBUSER, DBPASS, DBNAME);

  $filParent = $dircn->getById($filIdParent);

  if($filParent !== false){

    if($dircn->alt($filParent['id'], $filParent['parent'], $filParent['name'], $filParent['subdir'], $filParent['file'] + 1, $filParent['uid'])){

      require_once $BASE_PATH . 'm/bookmark.php';
      $bmcn = new Bookmark(DBHOST, DBUSER, DBPASS, DBNAME);
      $bookmark = $bmcn->get($UID);

      echo '{"code": 0, "data":' . json_encode($bookmark) . '}';

    }else{

      echo '{"code": 1, "message": "fail to change file of parent"}';

    }

  }else{

    echo '{"code": 2, "message": "fail to add fil"}';

  }

}
